package com.example.statistics.ui.bank

import androidx.fragment.app.FragmentActivity
import com.example.statistics.bean.StatementBean
import com.example.statistics.ex.httpGet
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.example.statistics.utils.DefaultConfig
import com.example.statistics.utils.activityForResult
import org.jetbrains.anko.startActivity

object Config {
    fun FragmentActivity.toStatementActivity(func: String, functionId: Int, money: Double?, result: () -> Unit) {

        httpGet<List<StatementBean>>(UrlConfig.BANK_STATEMENT_LIST,
            config = {
                listParams = listOf(
                    "function" to func,
                    "functionId" to functionId
                )
            }
        ) {
            if (it.isNullOrEmpty()) {
                activityForResult<StatementAddActivity>(
                    Constants.FUNCTION to func,
                    Constants.FUNCTION_ID to functionId,
                ) {
                    result.invoke()
                }
            } else {
                startActivity<StatementListActivity>(
                    Constants.FUNCTION to func,
                    Constants.FUNCTION_ID to functionId,
                    Constants.DATA to money
                )
            }
        }


    }

}